﻿using System.Collections.Generic;
using System.Windows.Forms;
using DevExpress.XtraEditors.DXErrorProvider;

namespace ContractManager.Common.Class
{
    public  class CustomValidation 
    {
        private readonly DXValidationProvider _provider; 

        
        public List <ControlRule> RuleList { get ; set ;} 

        public CustomValidation () 
        {
            _provider = new DXValidationProvider(); 
        } 

       
        public  bool Validate () 
        {
            bool flag = true;
            if (_provider != null) 
            {
                _provider.Dispose(); 
            } 
            if (RuleList != null ) 
            {
                foreach (ControlRule item in RuleList) 
                {
                    _provider.SetIconAlignment(item.control, ErrorIconAlignment.MiddleRight);
                    _provider.SetValidationRule(item.control, item.rule); 
                } 
                flag = _provider.Validate (); 
            } 
            else 
            { 
                flag = false ; 
            } 
            return flag; 
        } 
    }
}
